<template>
  <section class="login">
    <div class="container">
      <div>
        <div class="page-account-top">
          <div class="login-name">
            <img src="../../assets/images/login_name1.png" alt="" />
          </div>
          <div class="page-account-top-logo">个人博客管理系统</div>
        </div>
        <Form ref="form" :model="d" :rules="rule" class="login-form">
          <FormItem label="账户名" prop="name">
            <Input v-model="d.name" size="large"></Input>
          </FormItem>
          <FormItem label="密码" class="password" prop="password">
            <Input
              v-model="d.password"
              type="password"
              @on-enter="submit"
              size="large"
            ></Input>
          </FormItem>
        </Form>
        <div class="submit" @click="submit">
          <Button :loading="loading" type="primary" width="100%" size="large">
            登 录
          </Button>
        </div>
      </div>
    </div>
  </section>
</template>

<script>
import { login } from '@/api/server.js';
export default {
  data() {
    return {
      loading: false,
      d: {
        name: "",
        password: "",
      },
      rule: {
        name: [
          { required: true, message: "账户名不能为空", trigger: "blur" },
        ],
        password: [
          { required: true, message: "密码不能为空", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    submit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          login(this.d).then(res => {
            if(res.data.isOk) {
              sessionStorage.username = res.data.username;
              let menuCode = 'myBlog', menuName = '我的博客', parentMenuName = '博客管理';
              sessionStorage.setItem('curMenu',parentMenuName+'-'+menuName);
              this.$router.push({ path: '/my-blog', query: { menuCode, menuName, parentMenuName }});
            }else {
              $Message.error(res.data.msg || '账户名或密码错误')
            }
          })
        }
      });
    },
  },
};
</script>
<style lang="less" scoped>
.login {
  position: fixed;
  display: flex;
  justify-content: center;
  align-items: center;
  top: 0;
  left: 0;
  z-index: 999;
  background-image: url("../../assets/images/login_bg3.jpg");
  background-size: 100% 100%;
  width: 100%;
  height: 100%;
  background-color: #fff;
  .container {
    width: 430px;
    padding: 32px 65px;
    background: rgba(255, 255, 255, 0.8);
    border-radius: 9px;
    box-shadow: 0px 10px 20px 0px rgba(66, 70, 86, 0.1),
      0px 10px 20px 0px rgba(0, 0, 0, 0.02) inset;
    border: 1px solid #ffffff;
    .page-account-top {
      padding: 0 0 32px;
      .login-name {
        margin: 0 auto;
      }
      .login-name img {
        height:50px;
        margin: 0 auto 8px;
        display: block;
      }
      .page-account-top-logo {
        color: #545454;
        font-size: 28px;
        text-align: center;
      }
      .page-account-top-desc {
        text-align: center;
        font-size: 14px;
        color: #808695;
      }
    }

    .name,
    .password {
      position: relative;
      span.login-icon {
        position: absolute;
        left: 0px;
        top: 0px;
        width: 32px;
        height: 32px;
        z-index: 1;
        i {
          line-height: 32px;
          padding: 0 10px;
        }
      }
      margin-bottom: 24px;
      .login-input {
        .ivu-input {
          padding-left: 12px;
        }
        height: 40px;
      }
      .error-msg {
        color: red;
      }
    }
  }
  .inner-footer {
    position: absolute;
    bottom: 0;
    width: 100%;
    text-align: center;
    background-color: transparent;
  }
}
</style>
<style lang="less">
.login-input {
  .ivu-input {
    padding-left: 32px;
  }
  height: 40px;
}
.submit button {
  width: 100%;
  height: 50px !important;
  line-height: 50px !important;
  border-radius: 4px !important;
  background: #ffb403 !important;
  box-shadow: 0px 6px 16px -3px rgba(255, 180, 3, 0.25) !important;
  border: none !important;
  &>span {
    font-size: 20px !important;
    font-weight: 500;
  }
}
.login {
  .login-form {
    .ivu-form-item {
      margin-bottom: 24px !important;
      .ivu-form-item-label {
        color: #9d9fa7;
        font-size: 12px;
        &:before {
          content: "" !important;
        }
      }
    }
    .ivu-input {
      border: 0;
      border-bottom: #eaecf1 1px solid;
      font-size: 18px !important;
      color: #424656;
    }
    .ivu-input:-webkit-autofill {
      -webkit-text-fill-color: #333;
      -webkit-box-shadow: 0 0 0px 1000px white inset !important; /**通过边框阴影遮挡住背景*/
    }
    .password {
      margin-bottom: 40px !important;
    }
    .ivu-input-wrapper-large .ivu-input-prefix i,
    .ivu-input-wrapper-large .ivu-input-suffix i {
      line-height: 30px;
    }
  }
}
</style>
